package coder.user.controller;

import coder.common.Result;
import coder.user.entity.Address;
import coder.user.service.IAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("address")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @PostMapping("add")
    public Result<String> saveAddress(@ModelAttribute  Address address) {
        addressService.saveAddress(address);
        return Result.success("新增成功");
    }

    @GetMapping("query")
    public Result<List<Address>> queryAddress() {
        List<Address> addressList = addressService.queryAddress();
        return Result.success(addressList);
    }

    @PostMapping("update")
    public Result<String> updateAddress(@ModelAttribute  Address address) {
        addressService.updateById(address);
        return Result.success("修改成功");
    }

    @PostMapping("del")
    public Result<String> delAddress(@RequestParam  String id) {
        Address address = addressService.getById(id);
        address.setIsDelete(1);
        addressService.updateById(address);
        return Result.success("删除成功");
    }
}
